package com.buding.fx.service;


import com.alibaba.fastjson.JSON;
import com.buding.fx.common.constant.CssStyleInfo;
import com.buding.fx.common.constant.MenuInfo;
import com.buding.fx.dao.MenuDao;
import com.buding.fx.dao.impl.MenuDaoImpl;
import com.buding.fx.entity.*;
import com.buding.fx.service.impl.CenterBuildService;
import com.buding.fx.service.impl.LeftPinaBuildService;
import com.buding.fx.service.impl.TopPinaBuildService;
import com.buding.fx.utils.TreeBuildUtils;
import javafx.scene.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * @author mingdongwei-jwk
 * @date 2022/09/13 18:14
 * @class com.buding.fx.service
 * @Description
 */
public class SystemInitService {
    Logger logger = LoggerFactory.getLogger(SystemInitService.class);

    public SystemConfigInfo initSysConfig(){
        logger.info("**********init start**********");
        SystemConfigInfo sysConfigInfo = new SystemConfigInfo();
        sysConfigInfo.setMenus(initTreeNode(1l));
        logger.info("menus init end, menus info:  "+sysConfigInfo.getMenus());
        CssStyleInfo css = new CssStyleInfo();
        css.forResize(0.3,0.2,0.6,0.25);
        sysConfigInfo.setCss(css);
        logger.info("system css init, css info: "+ JSON.toJSON(css));
        sysConfigInfo.setVersion(css.getVersion());
        sysConfigInfo.setUserInfo(getUserInfo(1l));
        return sysConfigInfo;
    }

    private List<Menu> initTreeNode(Long  userId){
        MenuDao menuDao = new MenuDaoImpl();
        List<Menu> menus = menuDao.selectAll();
        return menus;

    }

    private User getUserInfo(Long userId){
        User use = new User();
        use.setId(1l);
        use.setNickName("zhangsan");
        return use;
    }

    public Node getTopNode(SystemConfigInfo systemConfigInfo){
        TopPinaBuildService topPinaBuildService = new TopPinaBuildService();
        return topPinaBuildService.show(systemConfigInfo);
    }

    public Node getLeftNode(Node topNode,SystemConfigInfo systemConfigInfo){
        LeftPinaBuildService leftPinaBuildService = new LeftPinaBuildService();
        return leftPinaBuildService.show(systemConfigInfo);
    }

    public Node getCenter(Node leftNode,SystemConfigInfo systemConfigInfo){
        CenterBuildService centerBuildService = new CenterBuildService();
        return centerBuildService.onclickShow(leftNode,systemConfigInfo);
    }
}
